const _set = (key, value) => {
  window.localStorage.setItem(key, value)
}
const _get = (key) => {
  return window.localStorage.getItem(key)
}

const _setSession = (key, value) => {
  window.sessionStorage.setItem(key, value)
}
const _getSession = (key) => {
  return window.sessionStorage.getItem(key)
}

export const keys = {
  user: 'userinfo', // 用户信息
  shopinfo: 'shopinfo', // 店铺信息
  config: 'config',
  devid: 'devid',
  errorPage: 'errorPage',
  wxConfig: 'wxConfig', // 微信appid以及appsecret
  wxInitStep: 'wxInitStep', // 微信登录的步骤
  actaddress: 'actaddress', // 提货地址
  homeSelectedInfo: 'homeSelectedInfo', // 首页选中信息
  homeSearchHistory: 'homeSearchHistory', // 搜索结果
  mvUri: 'mv-uri', // 活动分享url
  scenes: 'scenes', // 场景数据
  version: 'version',
  addressItem: 'addressItem',
  addressOrder: 'addressOrder'
}
export const setCache = (name, content) => {
  if (!name) {
    return
  }
  if (typeof content !== 'string') {
    content = JSON.stringify(content)
  }
  _set(name, content)
}
export const getCache = name => {
  if (!name) {
    return
  }
  return _get(name)
}
export const removeCache = name => {
  if (!name) {
    return
  }
  window.localStorage.removeItem(name)
}
export const clearCache = () => {
  window.localStorage.clear()
}

// session
export const setSCache = (name, content) => {
  if (!name) {
    return
  }
  if (typeof content !== 'string') {
    content = JSON.stringify(content)
  }
  _setSession(name, content)
}
export const getSCache = name => {
  if (!name) {
    return
  }
  return _getSession(name)
}
export const removeSCache = name => {
  if (!name) {
    return
  }
  window.sessionStorage.removeItem(name)
}
export const clearSCache = () => {
  window.sessionStorage.clear()
}
